package com.kang.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.kang.dao.WarehouseOrderMapper;
import com.kang.pojo.WarehouseOrder;
import com.kang.pojo.WarehousePoJo;
import com.kang.service.warehouseOrderService;
import com.vonechina.entity.page.WareHouseOrderPage;

/**
 * 采购入库服务Impl
 * 
 * @author ysq
 *
 */
@Service
public class warehouseOrderServiceImpl implements warehouseOrderService {
	/**
	 * 采购入库Mapper
	 */
	@Resource
	private WarehouseOrderMapper who;

	/**
	 * 根据purchaseOrdereID查询采购入库信息
	 */
	@Override
	public WarehouseOrder selectonePurchaseOrder(int purchaseordereid) {

		return who.selectByPrimaryKey(purchaseordereid);
	}
	
	/**
	 * 保存采购入库信息
	 */
	@Override
	public int insertone(WarehouseOrder wo) {

		return who.insertSelective(wo);
	}

	/**
	 * 根据warehouseNumber查询采购入库信息
	 */
	@Override
	public WarehouseOrder selectoneid(String warehousenumber) {

		return who.selectoneid(warehousenumber);
	}

	/**
	 * 查询采购入库
	 */
	@Override
	public List<WarehousePoJo> selectByWheres(
			WareHouseOrderPage wareHouseOrderPage) {
		wareHouseOrderPage.setRows(who.selectByWherescount(wareHouseOrderPage));// 设置总条数
		return who.selectByWheres(wareHouseOrderPage);
	}
	@Override
	public List<WarehousePoJo> selectoneid2(String warehousenumber) {
		return who.selectoneid2(warehousenumber);
	}

	/**
	 * 生成采购入库订单号
	 */
	@Override
	public String selectMaxWarehouseNumber() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String text = sdf.format(new Date()) + "0001";
		Long no = Long.parseLong(text);
		String max = who.selectMaxWarehouseNumber();
		Long l = 0l;
		if (max != null) {
			l = Long.parseLong(max.replaceAll("[a-zA-Z]", ""));
		}
		if (l >= no) {
			no = l + 1;
		}
		return "RK" + no;
	}

	/**
	 * 修改采购入库信息
	 */
	@Override
	public int updateByPrimaryKeySelective(WarehouseOrder record) {
		return who.updateByPrimaryKeySelective(record);
	}

	/**
	 * 根据purchaseordereid删除WarehouseOrder
	 * 
	 * @param purchaseordereid
	 * @return
	 */
	@Override
	public int delWarehouseOrder(Integer purchaseordereid) {
		return who.delWarehouseOrder(purchaseordereid);
	}

	

	




}
